/*
 dEngine Source Code 
 Copyright (C) 2009 - Fabien Sanglard
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

//
//  dEngineAppDelegate.m
//  dEngine
//
//  Created by fabien sanglard on 09/08/09.
//

#import "dEngineAppDelegate.h"
#import "dEngineViewController.h"
#import "EAGLView.h"
#import "camera.h"

const float MAX_FPS = 1.0/60.0;
const float IDLE_FPS = 1.0/5.0;

@implementation dEngineAppDelegate

@synthesize window;
@synthesize glView;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame: [UIScreen mainScreen].bounds];
    self.glView = [[EAGLView alloc] initWithFrame: CGRectMake(0, 0, self.window.bounds.size.height, self.window.bounds.size.width)];
	[self.glView startAnimation];
    
    dEngineViewController* _mainPage = [[dEngineViewController alloc] initWithNibName: nil bundle: nil];
    _mainPage.view = self.glView;
    
    self.window.rootViewController = _mainPage;
    [self.window makeKeyAndVisible];
    
    [[UIApplication sharedApplication] setStatusBarHidden: YES];
    
    return YES;
}

- (void) applicationWillResignActive:(UIApplication *)application
{
	[glView stopAnimation];
}

- (void) applicationDidBecomeActive:(UIApplication *)application
{
	[glView startAnimation];
}

- (void)applicationWillTerminate:(UIApplication *)application
{
	[glView stopAnimation];
}

- (void) stopEngineActivity
{
	[glView stopAnimation];
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    //No multi-tasking, when you die, you die. Period.
	exit(0);
	//[self stopEngineActivity];
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
	[glView startAnimation];
}

- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)pWindow {
    return UIInterfaceOrientationMaskLandscape;
}

- (void)dealloc
{
    window = nil;
    glView = nil;
}


@end
